﻿#ifndef BASESERIAL_H
#define BASESERIAL_H

#include <QObject>
#include "qextserialport.h"
#include <QByteArray>

#define QSerialPortName(val) QString("COM") + QString::number(val)
typedef struct serialPortDataType
{
	 BaudRateType baudRate;
	 DataBitsType dataBit;
	 ParityType parity;
	 StopBitsType stopBit;
	 serialPortDataType():baudRate(BaudRateType::BAUD115200),dataBit(DataBitsType::DATA_8),
						  parity(ParityType::PAR_NONE),stopBit(StopBitsType::STOP_1){}
}serialPortType,*PserialPortType;
class CSerial : public QObject
{
    Q_OBJECT
public:
    explicit CSerial(QObject *parent = 0);
    virtual ~CSerial();
    bool OpenSerial(quint8 portNumber,QIODevice::OpenModeFlag openMode = QIODevice::ReadWrite);
    void CloseSerial();
	QextSerialPort* GetSerial(){return m_pSerial;}
signals:
    void ReadSerial();
public slots:
	void SendData(const char* data, quint64 len);
	void SendData(QByteArray _data);
protected:
    QextSerialPort *m_pSerial;
private:
	serialPortType m_seialPortAttribute;
	void SetPortAttribute(const serialPortType& seialPortAttribute){m_seialPortAttribute = seialPortAttribute;}
};

#endif // BASESERIAL_H
